<template>
  <div>
    <el-container style="height: 100vh">
      <el-aside
        class="aside"
        :style="{ width: `${isCollapse ? 65 : 240}px`, transition: '0.4s' }"
      >
        <el-menu
          unique-opened
          router
          :default-active="$route.path"
          background-color="#345"
          text-color="#bbb"
          :style="{ height: '100vh' }"
          :collapse="isCollapse"
          class="el-menu-vertical-demo"
        >
          <el-menu-item>
            <template slot="title">
              <span style="font-size: 1.2em; color: #efefef; font-weight: bold"
                >&nbsp;&nbsp;青年旅舍后台管理</span
              >
            </template>
          </el-menu-item>
          <el-menu-item index="/home/index">
            <i class="el-icon-s-home"></i>
            <template slot="title"> 首页 </template>
          </el-menu-item>
          <el-submenu index="/home/user">
            <template slot="title">
              <i class="el-icon-user"></i>
              <span slot="title">用户管理</span>
            </template>
            <el-menu-item index="/home/user-list">
              <i class="el-icon-notebook-2"></i>
              <span slot="title">用户列表</span>
            </el-menu-item>
          </el-submenu>

          <el-submenu index="/home/order">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span slot="title">订单管理</span>
            </template>
            <el-menu-item index="/home/order-list">
              <i class="el-icon-notebook-2"></i>
              <span slot="title">订单列表</span>
            </el-menu-item>
          </el-submenu>

          <el-submenu index="/home/room">
            <template slot="title">
              <i class="el-icon-office-building"></i>
              <span slot="title">酒店管理</span>
            </template>
            <el-menu-item index="/home/room-list">
              <i class="el-icon-notebook-2"></i>
              <span slot="title">酒店列表</span>
            </el-menu-item>
          </el-submenu>

          <el-submenu index="/home/spot">
            <template slot="title">
              <i class="el-icon-postcard"></i>
              <span slot="title">景点管理</span>
            </template>
            <el-menu-item index="/home/spot-list">
              <i class="el-icon-notebook-2"></i>
              <span slot="title">景点列表</span>
            </el-menu-item>
          </el-submenu>

          <el-submenu index="/home/note">
            <template slot="title">
              <i class="el-icon-edit"></i>
              <span slot="title">攻略管理</span>
            </template>
            <el-menu-item index="/home/note-list">
              <i class="el-icon-notebook-2"></i>
              <span slot="title">攻略列表</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>

      <el-container>
        <el-header class="header">
          <i
            v-show="!isCollapse"
            class="el-icon-s-fold"
            @click="isCollapse = true"
          ></i>
          <i
            v-show="isCollapse"
            class="el-icon-s-unfold"
            @click="isCollapse = false"
          ></i>
          <!-- 面包屑导航 -->
          <el-breadcrumb separator="/" class="breadcrumb">
            <el-breadcrumb-item v-for="item in $route.meta.nav" :key="item">
              {{ item }}
            </el-breadcrumb-item>
          </el-breadcrumb>
          <span v-if="user"> 欢迎：{{ user.uname }}</span>
          <span v-else>未登录</span>
        </el-header>

        <el-main>
          <!-- 二级路由 动态设置内容 -->
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  data() {
    return {
      isCollapse: false,
    }
  },
  computed: {
    ...mapState(['user']),
  },
}
</script>

<style lang="scss" scoped>
.header {
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ccc;

  i {
    font-size: 1.3em;
  }

  .breadcrumb {
    margin-left: 20px;
    flex: 1;
  }
}
.aside::-webkit-scrollbar {
  display: none;
}
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 240px;
  min-height: 400px;
}
</style>
